/*
package com.friend.chat.media.video

import android.util.Log
import android.view.View
import com.friend.chat.base.BaseFragment
import com.friend.chat.base.BasicViewModel
import com.friend.chat.chat.*
import com.friend.chat.databinding.FragmentVideoBinding
import com.friend.chat.page.bean.UserBean
import com.friend.chat.utils.SPUtils
import com.friend.chat.webrtc.IWebRtcCallback
import com.friend.chat.webrtc.WebRtcEngine
import com.friend.chat.webrtc.renderer.ProxyVideoSink
import com.friend.chat.websocket.ChatMessageBean
import com.friend.chat.websocket.WebSocketManager
import com.google.gson.Gson
import org.greenrobot.eventbus.EventBus
import org.greenrobot.eventbus.Subscribe
import org.greenrobot.eventbus.ThreadMode
import org.webrtc.MediaStream
import org.webrtc.RendererCommon
import org.webrtc.SessionDescription
import org.webrtc.SurfaceViewRenderer
import java.util.*

*/
/**
 * @des
 * @author batie fancy
 * @date 2023/4/14
 *//*

class FragmentVideo : BaseFragment<FragmentVideoBinding, BasicViewModel>() {
    private var isCall: Boolean = true
    private var mToUid: String = ""
    private lateinit var userBean: UserBean
    private var mWebRtcEngine: WebRtcEngine? = null
    private val TAG = "FragmentVideo"

    override fun yourViewModel(): BasicViewModel = BasicViewModel()

    override fun yourViewBing(): FragmentVideoBinding {
        return FragmentVideoBinding.inflate(layoutInflater)
    }

    override fun init() {
        userBean = SPUtils.getInstance().getObject("user") as UserBean
        isCall = requireArguments().getBoolean("isCall", true)
        mToUid = requireArguments().getString("toUid") ?: ""
       initWebrtc()
    }

    private fun initWebrtc() {
        val uuid = UUID.randomUUID().toString()
        mWebRtcEngine = WebRtcEngine(requireContext(), false, object : IWebRtcCallback {
            override fun sendOffer(sdp: SessionDescription?) {

                sdp?.apply {
                    val map = HashMap<String, String>()
                    map["type"] = SIGNAL_OFFER
                    map["sdp"] = sdp.description
                    WebSocketManager.instance.sendMessage(
                        Gson().toJson(
                            ChatMessageBean(
                                userId = userBean.uid,
                                toUid = mToUid,
                                type = CHAT_VIDEO,
                                roomType = CHAT_ROOM_SINGLE,
                                roomId = uuid,
                                message = map
                            )
                        )
                    )
                }

            }

            override fun sendAnswer(sdp: SessionDescription?) {

                sdp?.apply {
                    val map = HashMap<String, String>()
                    map["type"] = SIGNAL_ANSWER
                    map["sdp"] = sdp.description
                    WebSocketManager.instance.sendMessage(
                        Gson().toJson(
                            ChatMessageBean(
                                userId = userBean.uid,
                                toUid = mToUid,
                                type = CHAT_VIDEO,
                                roomType = CHAT_ROOM_SINGLE,
                                roomId = uuid,
                                message = map
                            )
                        )
                    )
                }

            }

            override fun sendIceCandidate(sdpMid: String?, sdpMLineIndex: Int, sdp: String?) {
                Log.e(TAG, "sendIceCandidate: sendIceCandidate")
                val map = HashMap<String, Any>()
                map["type"] = SIGNAL_CANDIDATE
                map["sdpMid"] = sdpMid ?: ""
                map["sdpMLineIndex"] = sdpMLineIndex
                map["sdp"] = sdp ?: ""
                WebSocketManager.instance.sendMessage(
                    Gson().toJson(
                        ChatMessageBean(
                            userId = userBean.uid,
                            toUid = mToUid,
                            type = CHAT_VIDEO,
                            roomType = CHAT_ROOM_SINGLE,
                            roomId = uuid,
                            message = map
                        )
                    )
                )
            }

            override fun onRemoteStream(stream: MediaStream?) {
                val renderer = SurfaceViewRenderer(requireContext())
                renderer.setScalingType(RendererCommon.ScalingType.SCALE_ASPECT_FILL)
                renderer.setMirror(true)
                renderer.setZOrderMediaOverlay(true)
                val sink = ProxyVideoSink()
                sink.setTarget(renderer)
                stream?.apply {
                    stream.videoTracks[0].addSink(sink)
                    mViewBing.pipVideoView.addView(renderer)
                }
            }
        })
        mWebRtcEngine?.personIn(userBean.uid, mToUid)
        val view: View? = mWebRtcEngine?.setupLocalPreview(false)
        view?.apply {
            val localSurfaceView = view as SurfaceViewRenderer
            mViewBing.fullscreenVideoView.addView(localSurfaceView)
        }
    }

    @Subscribe(threadMode = ThreadMode.MAIN)
    fun onMessageEvent(event: ChatMessageBean?) {
        event?.apply {
            if (event.type == CHAT_VIDEO && event.roomType == CHAT_ROOM_SINGLE) {
                val map = event.message as kotlin.collections.HashMap<*, *>
                val type = map["type"]
                //接收者：接收到offer
                if (SIGNAL_OFFER == type) {
                    Log.e(TAG, "onMessageEvent: receiveOffer")
                    mWebRtcEngine?.receiveOffer(userBean.uid, map["sdp"].toString())
                }
                //发送者：接收到answer
                else if (SIGNAL_ANSWER == type) {
                    Log.e(TAG, "onMessageEvent: receiveAnswer")
                    mWebRtcEngine?.receiveAnswer(userBean.uid, map["sdp"].toString())

                }
                //所有参与的
                else if (SIGNAL_CANDIDATE == type) {
                    Log.e(TAG, "onMessageEvent: receiveIceCandidate")
                    mWebRtcEngine?.receiveIceCandidate(
                        userBean.uid,
                        map["sdpMid"].toString(),
                        map["sdpMLineIndex"] as Int,
                        map["sdp"].toString()
                    )
                }
            }


        }
    }

    override fun onDestroy() {
        if (EventBus.getDefault().isRegistered(this)) {
            EventBus.getDefault().unregister(this)
        }
        super.onDestroy()

    }
}*/
